package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int)
	quit := make(chan bool)

	go func() {
		for {
			select {
			case num := <-ch:
				fmt.Println(num)
			case <-time.After(3 * time.Second):
				quit <- true
				goto label //在一个函数中跳转到label标签处
			}
		}
	label:
		fmt.Println("break to label")
	}()
	for i := 0; i < 3; i++ {
		ch <- i
		time.Sleep(time.Second * 2)
	}
	<-quit //主goroutine阻塞，等待子goroutine通知
	fmt.Println("主程序退出")
}
